package kr.co.nextree.android.sample.activity;

import kr.co.nextree.android.sample.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class SampleOptionMenuXml extends Activity {
	private Button mBtnOpen;
	private Button mBtnClose;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.option_menu_layout);
		
		mBtnOpen = (Button)findViewById(R.id.open);
		mBtnOpen.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				openOptionsMenu();
			}
		});
		
		mBtnClose = (Button)findViewById(R.id.close);
		mBtnClose.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				closeOptionsMenu();
			}
		});
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = new MenuInflater(this);
		inflater.inflate(R.menu.option_menu, menu);
		
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.menuOne:
		case R.id.menuTwo:
		case R.id.menuThree:
		case R.id.menuFour:
		case R.id.menuFive:
		case R.id.menuSix:
		case R.id.menuSeven:
			Toast.makeText(this, "메뉴호출", Toast.LENGTH_SHORT).show();
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		menu.setGroupEnabled(R.id.groupOne, false);
		return super.onPrepareOptionsMenu(menu);
	}
	
	
	

}
